const http = require('http');
const chalk = require('chalk');
const conf = require('./config/defaultConfig');

const server = http.createServer((req, res) => {
  // res.statusCode = 200;
  // res.setHeader('Content-Type','text/plain;charset=utf8');
  // response.setHeader() 设置的响应头会与 response.writeHead() 设置的响应头合并，且 response.writeHead() 的优先。
  res.writeHead(200, {'Content-Type':'text/html;charset=utf8'});
  res.write(`
    <html>
      <head>
        <title>Hello</title>
      </head>
      <body>
        <h3>你好, 世界</h3>
        <small>Hello, World !</small>
        <p>
          Talk is Cheap, Show me the CODE
        </p>
      </body>
    </html>
  `);
  res.end();
});

server.listen(conf.port, conf.hostname, () => {
  const addr = `http://${conf.hostname}:${conf.port}`;
  console.info(`Server started at ${chalk.green(addr)}`);
});
